package com.eboss2.sbs.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.model.TxRecordDetail;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TxRecordDetailActivity extends BaseActivity {

    private static final String TAG = "TxRecordDetailActivity";

    @BindView(R.id.titleback_btn_back)
    LinearLayout titlebackBtnBack;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_trans_type)
    TextView tvTransType;
    @BindView(R.id.tv_account)
    TextView tvAccount;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.tv_settle_amt)
    TextView tvSettleAmt;
    @BindView(R.id.tv_balance_amt)
    TextView tvBalanceAmt;
    @BindView(R.id.tv_card_no)
    TextView tvCardNo;
    @BindView(R.id.tv_refuse)
    TextView tvRefuse;

    private long recordId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_tx_record_detail);
        ButterKnife.bind(this);
        MyActivityManager.getInstance().addActivity(this);
        initView();

        recordId = getIntent().getLongExtra("recordId", 0);
        if (recordId != 0) {
            getdata();
        }
    }

    private void initView() {
        RelativeLayout relativeLayout = relativeLayout(R.id.lv_heard);
        relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
        showView(R.id.titleback_btn_back, true);
        setTvText(R.id.tv_title, "提现详情 ");


    }


    @OnClick(R.id.titleback_btn_back)
    public void onViewClicked() {
        finish();
    }


    private void getdata() {

        showProgress("加载中...");
        RequestParams params = new RequestParams();
        params.put("id", recordId);
        HttpUtil.get(Config.SBS_TX_RECORD_DETAIL, params, new HttpUtil.RequestListener() {
            @Override
            public void success(String response) {
                disShowProgress();
                try {
                    JSONObject result = new JSONObject(response);

                    if (!result.optBoolean("status")) {
                        ToastUtils.CustomShow(mContext, result.optString("message"));
                    } else {
                        TxRecordDetail txRecordDetail = new Gson().fromJson(result.optString("data"), new TypeToken<TxRecordDetail>() {
                        }.getType());
                        if (txRecordDetail != null) {
                            tvAmount.setText(StringUtils.formatStrMoney(txRecordDetail.getDrawAmount()));
                            tvStatus.setText(txRecordDetail.getStatus());
                            tvTransType.setText(txRecordDetail.getTransType());
                            tvAccount.setText(txRecordDetail.getShopName());
                            tvTime.setText(txRecordDetail.getGmtCreate());
                            tvOrderNo.setText(txRecordDetail.getOrderNo());
                            tvSettleAmt.setText(StringUtils.formatStrMoney(txRecordDetail.getDrawAmount()));
                            tvBalanceAmt.setText(StringUtils.formatStrMoney(txRecordDetail.getBalanceAmount()));
                            tvCardNo.setText(txRecordDetail.getBankName() + "(" + txRecordDetail.getBankNo() + ")");
                            tvRefuse.setText(StringUtils.isBlank(txRecordDetail.getAuditMemo()) ? "" : txRecordDetail.getAuditMemo());
                        }
                    }
                } catch (Exception e) {
                    Log.e(TAG, "doLogin() Exception: " + e.getMessage());
                }


            }

            @Override
            public void failed(Throwable error) {
                disShowProgress();
                showE404();
            }
        });
    }


}
